{% extends "users/auth.html" %}
{% load i18n %}{% load logic %}{% load ls %}{% load markup %}
{%block title%}{{form.instance.title}}{%endblock%}
{%block post%}
<li id="add"><a href="/add/" title="add post">{%trans "New post"%}</a></li>
<li id="edit"><span>{%trans "Edit"%}</span></li>
{%endblock%}
{%block meta%}
<script type="text/javascript" src="/media/jq/jquery.js"></script>
<script type="text/javascript" src="/media/jq/tag.js"></script>
<style type="text/css" media="screen">
.left {width: 72%;}
iframe {border: 0;clear:both;width:320px;}
span.tagMatches span {
padding: 2px;
margin-right: 4px;
background-color: #0000AB;
color: #fff;
cursor: pointer;
}
</style>
<script type="text/javascript">
var curcat = '{{form.curcat}}';
var tohide = {'anime': ['imdb', 'artist', 'album', 'company'],
'books': ['artist', 'album', 'year', 'company', 'tube', 'imdb', 'screenshot'],
'games': ['imdb', 'artist', 'album'],
'movies': ['artist', 'album', 'company'],
'music': ['screenshot', 'imdb', 'company', 'lngs', 'tube'],
'pics': ['imdb', 'artist', 'album', 'year', 'company', 'tube'],
'tv': ['artist', 'album', 'company'],
'misc': ['screenshot', 'imdb', 'artist', 'album', 'year', 'company', 'tube', 'lngs']
}
var toshow = {'anime': ['year', 'tube', 'lngs', 'screenshot'],
'books': ['lngs'],
'games': ['screenshot', 'year', 'company', 'lngs', 'tube'],
'movies': ['screenshot', 'imdb', 'year', 'tube', 'lngs'],
'music': ['album', 'artist', 'year'],
'pics': ['lngs'],
'tv': ['screenshot', 'imdb', 'year', 'tube', 'lngs'],
}
function jtocat(item, dflt){
var root = document.getElementById('subsubwrap');
var subsub = document.getElementById('subsub');
for(var i=0;i<tohide[item.value].length;i++){
 $('#'+tohide[item.value][i]).addClass('hidden');
}

if(item.value == 'misc'){
subsub.removeAttribute("name");
root.style.display = 'none';
return;
};
for(var i=0;i<toshow[item.value].length;i++){
 $('#'+tohide[item.value][i]).addClass('hidden');
}
subsub.parentNode.removeChild(subsub);

subsub = document.createElement("select");
subsub.id = 'subsub'
root.appendChild(subsub);

subsub.setAttribute("name", item.value);

var ti = document.getElementById(item.value);
if(!ti) return;

var opts = ti.getElementsByTagName('option');
for(var i=0;i<opts.length;i++){
 o = document.createElement('option');
 o.setAttribute('value', opts[i].value);
 if(dflt==opts[i].value){
  o.setAttribute("selected", "selected");
 }
 o.innerHTML = opts[i].firstChild.data;
 subsub.appendChild(o);
}
root.style.display = 'inline';
}

$(document).ready(function(){
$('#id_tags').tagSuggest({
 url: '/rpc/tags/'+curcat+'/',
 delay: 250
});

var h = document.getElementById("form-sub");
h.removeAttribute("name");
h.id = "hidden";
h.setAttribute("class", "hidden");

$('#cats').append('<div id="subwrapper"><select name="section" id="sub" onChange="jtocat(this);">{{form.section}}</select></div>');
$('#subwrapper').append('<div id="subsubwrap"></div>');
$('#subsubwrap').hide()
$('#subsubwrap').append('> <select id="subsub"></select>')

so = document.getElementById('sub').getElementsByTagName('option');
var co = '{{form.curcat}}';
if(!co) co = 'misc';
for(var i=0;i<so.length;i++){
 if(so[i].value == co){
  jtocat(so[i], '{{form.instance.subcat}}');
  break;
 }
}
});
</script>
{%endblock%}

{%block body%}<body id="editpost" class="yui-skin-sam">{%endblock%}

{%block content%}
<div id="panel"><div class="bd">&nbsp;</div></div>

<h1>{{form.instance.title}}</h1>
<form action="." name="editform" method="POST" enctype="multipart/form-data">
<div id="markup">
<div id="torrent" class="row"><label for="id_torrent">.torrent file<b>:</b>{%if form.instance.torrent%}<br><span class="gray">{{form.instance.torrent.fn}}</span>{%endif%}{%if form.torrent.errors%}<br><span class="error">{{form.torrent.errors}}<br></span>{%endif%}</label>{{form.torrent}}<br></div>
<div class="row"><label for="id_poster">{{form.poster.label}}<b>:</b>{%if form.poster.errors%}<span class="error"><br>{{form.poster.errors}}</span>{%endif%}</label>{{form.poster}}<br></div>

<div id="title" class="row"><label for="id_title">{{form.title.label}}<b>:</b>{%if form.title.errors%}<br><span class="error"><br>{{form.title.errors}}</span>{%endif%}</label>{{form.title}}<br></div>
<div id="tags" class="row"><span style="float:left;"><label for="id_tags">{{form.tags.label}}<b>:</b>{%if form.tags.errors%}<br><span class="error">{{form.tags.errors}}</span>{%endif%}</label><input id="id_tags" value="{%if form.instance.tags%}{%for tag in form.instance.tags%}{{tag}}{%if not forloop.last%}, {%endif%}{%endfor%}{%endif%}" type="text" maxlength="255" name="tags"></span><div id="tagc"></div><br></div>

<div class="row"><label>&nbsp;</label>{% autoescape off %}{{form.instance.text|bbcode}}{% endautoescape %}</div>
<div id="post_type" class="row"><label for="id_section">{%trans "category"%}<b>:</b>{%if form.section.errors%}<span class="erorr">{{form.section.errors}}</span>{%endif%}</label>
<div id="cats"><select id="form-sub" name="section">
<optgroup label="{%trans "Anime"%}" id="anime">{{form.anime}}</optgroup>
<optgroup label="{%trans "Books"%}" id="books">{{form.books}}</optgroup>
<optgroup label="{%trans "Games"%}" id="games">{{form.games}}</optgroup>
<optgroup label="{%trans "Movies"%}" id="movies">{{form.movies}}</optgroup>
<optgroup label="{%trans "Music"%}" id="music">{{form.music}}</optgroup>
<optgroup label="{%trans "Pictures"%}" id="pics">{{form.pics}}</optgroup>
<optgroup label="{%trans "TV"%}" id="tv">{{form.tv}}</optgroup>
<option value="misc">{%trans "Miscellaneous"%}</option></select>
</div></div>
<div id="company" class="row"><label for="id_company">{{form.company.label}}<b>:</b>{%if form.company.errors%}<br><span class="error"><br>{{form.company.errors}}<br></span>{%endif%}</label>{{form.company}}<br></div>
<div id="imdb" class="row"><br><label for="id_imdb">{{form.imdb.label}}<b>:</b>{%if form.imdb.errors%}<br><span class="error"><br>{{form.imdb.errors}}</span><br>{%endif%}</label><input id="id_imdb" type="text" name="imdb" value='{{form.instance.attrs|key:"imdb"}}'><br><br></div>
<div id="artist" class="row"><label for="id_artist">{{form.artist.label}}<b>:</b>{%if form.artist.errors%}<br><span class="error"><br>{{form.artist.errors}}<br></span>{%endif%}</label>{{form.artist}}<br></div>
<div id="album" class="row"><br><label for="id_album">{{form.album.label}}<b>:</b>{%if form.album.errors%}<br><span class="error"><br>{{form.album.errors}}<br></span>{%endif%}</label>{{form.album}}<br></div>
<div id="year" class="row"><br><label for="id_year">{{form.year.label}}<b>:</b>{%if form.year.errors%}<br><span class="error"><br>{{form.year.errors}}<br></span>{%endif%}</label><input id="id_year" type="text" maxlength="4" name="year" value='{{form.instance.attrs|key:"year"}}' style="width:3em;"><br></div>

<div id="tube" class="row"><label for="id_tube">{{form.tube.label}}<b>:</b>{%if form.tube.errors%}<span class="error"><br>{{form.tube.errors}}</span><br>{%endif%}</label>{{form.tube}}<br></div>
<div id="lngs" class="row"><label for="id_lngs">{{form.lngs.label}}<b>:</b>{%if form.lngs.errors%}<br><span class="error"><br>{{form.lngs.errors}}</span>{%endif%}</label>{{form.lngs}}<br></div>
<div id="featured" class="rr"><label>{{form.featured.label}}<b>:</b></label>Yes&nbsp;<input type="radio" name="featured" value="yes" {%if form.instance.attrs|key:"featured"|equal:"True"%}checked="checked"{%endif%}>No<input type="radio" name="featured" value="no" {%if not form.instance.attrs|key:"featured"|equal:"True"%}checked="checked"{%endif%}><br></div>
<div id="notify" class="rr"><label>{{form.notify.label}}<b>:</b></label>Yes&nbsp;<input type="radio" name="notify" value="yes" {%if form.instance.attrs|key:"notify"|equal:"True"%}checked="checked"{%endif%}>No<input type="radio" name="notify" value="no" {%if not form.instance.attrs|key:"notify"|equal:"True"%}checked="checked"{%endif%}><br></div>
<div class="sb"><label>&nbsp;</label><span class="button"><span class="first-child"><button type="submit">{%trans "Write"%}</button></span></span></div>

</div></form><br>

<h1>{{form.instance.title}}</h1>
<div class="article"><div class="body">
<p class="imageleft"><img src="/media/iposter/{{form.instance.poster}}"></p>
<p>{%if form.instance.attrs|key:"country"%}{%trans "country"%}<b>:</b> {{form.instance.attrs|key:"country"}}<br>{%endif%}
{%if form.instance.attrs|key:"artist"%}{%trans "artist"%}<b>:</b> {{form.instance.attrs|key:"artist"}}<br>{%endif%}
{%if form.instance.attrs|key:"album"%}{%trans "album"%}<b>:</b> {{form.instance.attrs|key:"album"}}<br>{%endif%}
{%if form.instance.attrs|key:"year"%}{%trans "year"%}<b>:</b> {{form.instance.attrs|key:"year"}}<br>{%endif%}
{%if form.instance.attrs|key:"company"%}{%trans "company"%}<b>:</b> {{form.instance.attrs|key:"company"}}<br>{%endif%}
{%if form.instance.attrs|key:"tube"%}{%trans "video"%}<b>:</b> <a href="{{form.instance.attrs|key:"tube"}}">URL</a><br>{%endif%}
{%if form.instance.attrs|key:"lngs"%}{%trans "languages"%}<b>:</b> {{form.instance.attrs|key:"lngs"}}<br>{%endif%}
{%if form.instance.attrs|key:"imdb"%}IMDB <b>:</b> <a href="{{form.instance.attrs|key:"imdb"}}">URL</a><br>{%endif%}
<br>{% autoescape off %}{{form.instance.text|bbcode}}{% endautoescape %}</p>
<div id="screenshot" class="hidden"><span id="scrs"></span>
<br><iframe id="scr_iframe" name="scr_iframe" src="/upload_scr/{{form.instance.id}}/"></iframe>
</div>
</div>
<div class="torrentbar"><p>.torrent: <a href="/torrent/{{form.instance.torrent.id}}/?redirect=/~{{user.username}}/{{form.instance.slug}}/">{%trans "download"%}</a></p></div>
<div class="footer"><h4 class="meta">{%trans "section"%}: </h4><p>'{{form.curcat|transcat}}'</p>
<h4 class="meta">{%trans "tags"%}: </h4><p>{%for tag in form.instance.tags|truncate:"3"%}<a href="/tag/{{tag.name}}/">{{tag.name}}</a>{%if not forloop.last%}, {%endif%}{%endfor%}{%if form.instance.tags|length|gt:"3"%} ..{%endif%}</p>
</div>

<br><br><br><br><br>
{%endblock%}
{%block right%}
<div class="rnote"><div class="right">
  <div class="round">
    <div class="roundtl"><span></span></div>
    <div class="roundtr"><span></span></div>
    <div class="clearer"><span></span></div>
  </div>
  <div class="subnav">
  <p>{%trans "After confirming by moderator post can not be changed"%}.</p>
  </div>
  <div class="round"><div class="roundbl"><span></span></div>
   <div class="roundbr"><span></span></div><span class="clearer"></span>
  </div>
</div>

{%if form.instance.slug%}
<div class="right">
  <div class="round">
    <div class="roundtl"><span></span></div>
    <div class="roundtr"><span></span></div>
    <div class="clearer"><span></span></div>
  </div>
  <div class="subnav">
  <p>URL: <a href="/~{{form.instance.author.username}}/{{form.instance.slug}}/">{{form.instance.title}}</a></p>
  </div>
  <div class="round"><div class="roundbl"><span></span></div>
   <div class="roundbr"><span></span></div><span class="clearer"></span>
  </div>
</div>
{% endif %}

</div>
{%endblock%}
